<?php

class PaisDAO extends DAO {
    public function select($fields='*', $condition='TRUE', $page='1', $rows_per_page='20', $order_by='id_pais', $order_by_type='DESC') {
        $list_pais = array();
        $data_pais = array();
        try {
            //$rows = 0;
            //$start = intval(($page-1)*$rows_per_page);
            //$query = "SELECT COUNT(id_pais) AS rows FROM pais";
            //$query .= " WHERE ".$condition;
            //$stmt = $this->dbh->query($query);
            //$rows = $stmt->fetchObject()->rows;
            $query = 'SELECT '. $fields .' FROM pais';
            $query .= ' WHERE '.$condition.' ';
            //$pages = ceil($rows/$rows_per_page);
            $query .= 'ORDER BY :order_by';
            $query .= ' :order_by_type ';
            //$query .= 'LIMIT :start, :rows_per_page';
            
            //$stmt->closeCursor();
            $stmt = $this->dbh->prepare($query);
            //$stmt->bindParam(':start', $start, PDO::PARAM_INT);
            //$stmt->bindParam(':rows_per_page', $rows_per_page, PDO::PARAM_INT);
            $stmt->bindParam(':order_by', $order_by);
            $stmt->bindParam(':order_by_type', $order_by_type);
            $stmt->setFetchMode(PDO::FETCH_OBJ);
            $stmt->execute();
            $result = $stmt->fetchAll();

            foreach($result as $row) {
                $objPaisTo = new PaisTO();
                $objPaisTo->setIdPais($row->id_pais);
                $objPaisTo->setNombre($row->nombre);
                $list_pais[count($list_pais)+1] = $objPaisTo;
            }
            $data_pais['list_pais']=$list_pais;
            //$data_pais['pages']=$pages;
            //$data_pais['rows']=$rows;

            return $data_pais;
            
        }catch(Exception $e) {
            throw $e;
        }
    }

    public function load($objCuentaTO) {
        return "";
    }

    public function delete($id) {
        return "";
    }

    protected function update($objetoTO) {
        return "";
    }

    protected function insert($objetoTO) {
        return "";
    }
}
?>
